package com.ruoyi.controller.admin.accounting;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.admin.AdminAccountingDB;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.admin.AdminAccountingService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/admin/accounting")
public class AdminAccountingController extends BaseController {

    @Resource
    private AdminAccountingService adminAccountingService;

    /**
     * 查询后台-记账列表
     */
    @PreAuthorize("@ss.hasPermi('accounting:accounting:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdminAccountingDB adminAccountingDB)
    {
        return adminAccountingService.selectAdminAccountingDBList(adminAccountingDB);
    }

    /**
     * 导出后台-记账列表
     */
    @PreAuthorize("@ss.hasPermi('accounting:accounting:export')")
    @Log(title = "后台-记账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdminAccountingDB adminAccountingDB)
    {
        List<AdminAccountingDB> list = (List<AdminAccountingDB>)adminAccountingService.selectAdminAccountingDBList(adminAccountingDB).getRows();
        ExcelUtil<AdminAccountingDB> util = new ExcelUtil<AdminAccountingDB>(AdminAccountingDB.class);
        util.exportExcel(response, list, "后台-记账数据");
    }

    /**
     * 获取后台-记账详细信息
     */
    @PreAuthorize("@ss.hasPermi('accounting:accounting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adminAccountingService.selectAdminAccountingDBById(id));
    }

    /**
     * 新增后台-记账
     */
    @PreAuthorize("@ss.hasPermi('accounting:accounting:add')")
    @Log(title = "后台-记账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminAccountingDB adminAccountingDB)
    {
        return toAjax(adminAccountingService.insertAdminAccountingDB(adminAccountingDB));
    }

    /**
     * 修改后台-记账
     */
    @PreAuthorize("@ss.hasPermi('accounting:accounting:edit')")
    @Log(title = "后台-记账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminAccountingDB adminAccountingDB)
    {
        return toAjax(adminAccountingService.updateAdminAccountingDB(adminAccountingDB));
    }

//    /**
//     * 删除后台-记账
//     */
//    @PreAuthorize("@ss.hasPermi('accounting:accounting:remove')")
//    @Log(title = "后台-记账", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(adminAccountingService.deleteAdminAccountingDBByIds(ids));
//    }


}
